package com.qf.ssm.controller;

import com.qf.ssm.common.request.OrderAppRequestParams;
import com.qf.ssm.common.request.OrderRequestParams;
import com.qf.ssm.common.vo.ResponseResult;
import com.qf.ssm.entity.Order;
import com.qf.ssm.service.OrderAppService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ISALYL
 * @create 2021-10-12 16:45
 */
@RestController
@RequestMapping("/order")
public class OrderAppController {
    @Resource
    private OrderAppService orderAppService;

    /**
     * 用户个人界面点击查看全部，通过用户ID查找订单表中所有该用户的订单
     * 返回VO类型还能完善
     *
     * @param memberId
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list/{memberId}")
    public ResponseResult<List<Order>> listOrder(@PathVariable("memberId") Long memberId,
                                                 @RequestParam(defaultValue = "1") Integer page,
                                                 @RequestParam(defaultValue = "10") Integer size) {
        List<Order> orders = orderAppService.listOrder(memberId, page, size);
        return ResponseResult.success(orders);

    }

    /**
     * 通过订单状态查找
     * 待付款 发货中等状态对应相应值
     *
     * @param memberId
     * @param orderName
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/find/{memberId}")
    public ResponseResult<List<Order>> findOrderByName(@PathVariable("memberId") Long memberId,
                                                       @RequestParam Long orderName,
                                                       @RequestParam(defaultValue = "1") Integer page,
                                                       @RequestParam(defaultValue = "10") Integer size) {

        List<Order> orders = orderAppService.findOrderByName(memberId, orderName, page, size);
        return ResponseResult.success(orders);
    }


    /**
     * 根据客户操作改变订单状态
     * @param params
     * @return
     */
    @PutMapping("/status")
    public ResponseResult<Integer> statusOrder(@RequestBody OrderRequestParams params) {
        Integer order = orderAppService.statusOrder(params);
        return ResponseResult.success(order);
    }

    /**
     * * 取消订单成功，将orderName置0
     *
     * @param params
     * @return
     */
    @PutMapping("/cancel")
    public ResponseResult<Integer> cancelOrder(@RequestBody OrderRequestParams params) {
        Integer order = orderAppService.cancelOrder(params);
        return ResponseResult.success(order);
    }

    /**
     * 成功下单，将orderName置1
     *
     * @param params
     * @return
     */
    @PutMapping("/mod")
    public ResponseResult<Integer> modOrder(@RequestBody OrderRequestParams params) {
        Integer order = orderAppService.modOrder(params);
        return ResponseResult.success(order);
    }

    /**
     * 成功付款，将orderName置2
     * @param params
     * @return
     */
    @PutMapping("/pay")
    public ResponseResult<Integer> payOrder(@RequestBody OrderRequestParams params) {
        Integer order = orderAppService.payOrder(params);
        return ResponseResult.success(order);
    }

    /**
     * 发货后，将orderName置3
     * @param params
     * @return
     */
    @PutMapping("/send")
    public ResponseResult<Integer> sendOrder(@RequestBody OrderRequestParams params) {
        Integer order = orderAppService.sendOrder(params);
        return ResponseResult.success(order);
    }

    /**
     * 成功收货后，将orderName置4
     * @param params
     * @return
     */
    @PutMapping("/receive")
    public ResponseResult<Integer> receiveOrder(@RequestBody OrderRequestParams params) {
        Integer order = orderAppService.receiveOrder(params);
        return ResponseResult.success(order);
    }

    /**
     * 评价完成,将orderName置5
     * @param params
     * @return
     */
    @PutMapping("/complete")
    public ResponseResult<Integer> completeOrder(@RequestBody OrderRequestParams params) {
        Integer order = orderAppService.completeOrder(params);
        return ResponseResult.success(order);
    }

    /**
     * 逻辑删除,将status置0
     * @param
     * @return
     */
    @DeleteMapping("/delete/{orderId}")
    public ResponseResult<Boolean> deleteOrder(@PathVariable("orderId") Long orderId){
        Boolean isDelete = orderAppService.deleteOrder(orderId);
        return ResponseResult.success(isDelete);
    }

}
